//ajax包装刷新方法
function CourseAjaxDefrence(){
    $.ajax({
        url: 'course/list.php',
        type: "POST",
        data: {
            size:courseSize,
            page:CoursePage,
            count:CourseMaxCount,
            list:[
                {
                    id:"id",
                    courseName:"name",
                    courseNo:"no"
                }
            ]
        },
        dataType: 'json',
        async: true,
        success: function (data) {
            query(data);
        },
    });
}
CourseAjaxDefrence();
//添加方法
$(function () {
    $("#courseAdd").click(function () {
        let courseName=$("#register .courseName").val();
        let courseNo=$("#register .courseNo").val();
        $.ajax({
            url: 'course/add.php',
            type:"POST",
            data: {
                "name":courseName,
                "courseNo":courseNo
            },
            dataType: 'json',
            async: true,
            success:function (data) {
                if(data.code==="200"){
                    $("#register").fadeOut(300);
                    CourseAjaxDefrence();
                }else {
                    alert(data.msg);
                }
            },
        });
    });
    //修改方法
    $("#courseChange").click(function () {
        let courseName=$("#changeCover .courseName").val();
        let courseNo=$("#changeCover .courseNo").val();
        let courseId=$("#changeCover #courseId").val();
        $.ajax({
            url: 'course/update.php',
            type:"POST",
            data: {
                "id":courseId,
                "courseName":courseName,
                "courseNo":courseNo,
            },
            dataType: 'json',
            async: true,
            success:function (data) {
                if(data.code==="200"){
                    CourseAjaxDefrence();
                    $("#changeCover").fadeOut(300);
                }else {
                    alert(data.msg);
                }
            },
        });
    });
});